<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>新增预登记</span>
        <el-button style="float: right; padding: 3px 0" type="text" @click="goBack">返回列表</el-button>
      </div>
      <pre-register-form ref="preRegisterForm" @submit="handleSubmit" @cancel="goBack" />
    </el-card>
  </div>
</template>

<script>
import PreRegisterForm from './components/PreRegisterForm'
import { save } from "@/api/room/preregister";

export default {
  name: "CreatePreRegister",
  components: {
    PreRegisterForm
  },
  methods: {
    handleSubmit(formData) {
      // 新增预登记
      save(formData).then(response => {
        if (response.code === 200) {
          this.$modal.msgSuccess("新增预登记成功");
          this.goBack();
        } else {
          this.$modal.msgError(response.msg || "新增失败");
        }
      }).catch(error => {
        console.error("新增预登记失败:", error);
        this.$modal.msgError("新增失败");
      });
    },
    goBack() {
      this.$router.push('/preregister');
    }
  }
};
</script> 